package designMode.statePattern.after;

/**
 * @author LIBOFEI
 * @ClassName SoldState
 * @description
 * @date 2020/6/28 16:49
 * @Version 1.0
 **/
public class SoldState implements State {

    GumballMachine machine;

    public SoldState(GumballMachine gumballMachine){
        this.machine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("您已购买糖果");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("您已拿到糖果，无法退币");
    }

    @Override
    public void turnCrank() {
        System.out.println("您已拿到糖果");
    }

    @Override
    public void dispense() {
        machine.repleaseBall();
        if(machine.getCount() > 0){
            machine.setState(machine.getNoQuarterState());
        }else{
            System.out.println("糖果售完");
            machine.setState(machine.getSoldOutState());
        }
    }
}
